package com.smart_campus.teg.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.sys.common.DataGridView;
import com.smart_campus.sys.domain.User;
import com.smart_campus.teg.vo.TegTalkVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.teg.mapper.TegTalkMapper;
import com.smart_campus.teg.domain.TegTalk;
import com.smart_campus.teg.service.TegTalkService;

import java.util.List;

@Service
public class TegTalkServiceImpl implements TegTalkService{

    @Resource
    private TegTalkMapper tegTalkMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.teg.service.impl.TegTalkServiceImpl",key = "#talkId")
    @Override
    public int deleteByPrimaryKey(Integer talkId) {
        return tegTalkMapper.deleteByPrimaryKey(talkId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegTalkServiceImpl",key = "#result.talkId")
    @Override
    public TegTalk insert(TegTalk record) {
        tegTalkMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegTalkServiceImpl",key = "#result.talkId")
    @Override
    public TegTalk insertSelective(TegTalk record) {
        tegTalkMapper.insertSelective(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.teg.service.impl.TegTalkServiceImpl",key = "#talkId")
    @Override
    public TegTalk selectByPrimaryKey(Integer talkId) {
        return tegTalkMapper.selectByPrimaryKey(talkId);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegTalkServiceImpl",key = "#result.talkId")
    @Override
    public TegTalk updateByPrimaryKeySelective(TegTalk record) {
        tegTalkMapper.updateByPrimaryKeySelective(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.teg.service.impl.TegTalkServiceImpl",key = "#result.talkId")
    @Override
    public TegTalk updateByPrimaryKey(TegTalk record) {
        tegTalkMapper.updateByPrimaryKey(record);
        return record;
    }

    @Override
    public DataGridView selTalk(TegTalkVo tegTalkVo) {
        Page<Object> page = PageHelper.startPage(tegTalkVo.getPage(),tegTalkVo.getLimit());
        List<TegTalk> list = tegTalkMapper.selAllTalk(tegTalkVo);
        return new DataGridView(page.getTotal(),list);
    }

    @Override
    public User selstudent(String studentName) {
        return tegTalkMapper.selstudent(studentName);
    }

}
